#if !defined(_CAMATH2D_H_)
#define _CAMATH2D_H_

#include "AObject.h"

class CARect 
{
public:
	float x, y;
	float w, h;
	
	CARect(float x_ = 0, float y_ = 0, float w_ = 0, float h_ = 0)
	{
		x = x_;
		y = y_;
		w = w_;
		h = h_;
	}
	CARect(const CCPoint& pt, const CCSize& siz)
	{
		x = pt.x;
		y = pt.y;
		w = siz.width;
		h = siz.height;
	}
	CARect(const CCRect& r)
	{
		x = r.origin.x;
		y = r.origin.y;
		w = r.size.width;
		h = r.size.height;
	}

	CARect unionWith(const CARect& r) const
	{
		CARect ret;
		ret.x = x < r.x ? x : r.x;
		ret.y = y < r.y ? y : r.y;
		float mx = x + w > r.x + r.w ? x + w : r.x + r.w;
		float my = y + h > r.y + r.h ? y + h : r.y + r.h;
		ret.w = mx - x;
		ret.h = my - y;
		return ret;
	}

	bool isIntersectWith(const CARect& r) const
	{
		return !(
			x + w < r.x ||
			r.x + r.w < x ||
			y + h < r.y ||
			r.y + r.h < y
			);
	}
};

#endif //_CAMATH2D_H_